﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;

namespace Sequence
{
    class CSqlString
    {
        public static string GetQuerydef(string sDBMS, string sQueryName)
        {
            string sRet = "";
            if (sDBMS == "OCI")
                sRet = "select id,query_name from t_api_querydef where lower(query_name) like '%" + sQueryName + "%'  and rownum < 100";
            else if (sDBMS == "MSS")
                sRet = "select top 1000 id,query_name from t_api_querydef where lower(query_name) like '%" + sQueryName + "%' ";
            return sRet;
        }

        public static string GetQuerydefProcess(string sDBMS, string sQueryName)
        {
            string sRet = "";
            if (sDBMS == "OCI")
                sRet = "select id,name from t_api_qd_process where lower(name) like '%" + sQueryName + "%'  and rownum < 100";
            else if (sDBMS == "MSS")
                sRet = "select top 1000 id,name from t_api_qd_process where lower(name) like '%" + sQueryName + "%' ";
            return sRet;
        }

        public static string RunSql(string sSql, OleDbConnection oConnection)
        {
            string sRet = "";
            try
            {
                OleDbCommand command = new OleDbCommand(sSql, oConnection);
                int iRows = command.ExecuteNonQuery();
                command.Dispose();
            }
            catch (Exception ex)
            {
                sRet  = ex.Message + " (" + sSql + ")\r\n";
            }
            return sRet;
        }
    }
}
